﻿#include "Node.h"

namespace DYEngine
{
	Node::Node(): name(""), mParent(nullptr) { }

	Node::Node(const std::string& pName): name(pName), mParent(nullptr) { }

	Node::~Node()
	{
		if (mParent != nullptr)
			mParent->RemoveChild(this);

		for (auto iter = mChildren.begin(); iter != mChildren.end(); iter++)
		{
			Node* child = (*iter);
			// 要设置子节点的父节点为空，不然删除子节点时，
			// 会调用RemoeChild()，导致容器遍历错误
			child->mParent = nullptr;
			delete child;
		}

		mParent = nullptr;
		mChildren.clear();
	}
}